import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TimeIntervalService } from '../timeInterval.service';

@Component({
  selector: 'app-zero',
  templateUrl: './zero.component.html',
  styleUrls: ['./zero.component.css'],
  providers: [TimeIntervalService],
})
export class ZeroComponent {
  httpUtils: HttpClient;
  timer: TimeIntervalService;
  baseUrl: string = 'https://www.codeboy.com/xuezi/data/product/index.php';
  constructor(http: HttpClient, timeInterval: TimeIntervalService) {
    this.httpUtils = http;
    this.timer = timeInterval;
  }
  login() {
    this.timer.start('登陆计时器');
    this.httpUtils.get(this.baseUrl).subscribe((res) => {
      console.log('数据', res);
      this.timer.end('登陆计时器');
    });
  }
  logout() {
    const stop = this.timer.timeFn('退出计时器');
    this.httpUtils.get(this.baseUrl).subscribe((res) => {
      console.log('数据', res);
      stop();
    });
  }
}
